<template>

  <el-form label-width="100px">
    <el-form-item label="金额">
      <el-input v-model="updateData.amount"/>
    </el-form-item>
    <el-form-item label="缴费类型">
      <el-select v-model="updateData.type" style="width: 100%">
        <el-option value="水费"></el-option>
        <el-option value="电费"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item v-if="!buttonName" style="text-align: right">
      <el-button type="primary" @click="paymentUpdate">修改缴费</el-button>
    </el-form-item>
    <el-form-item v-if="buttonName" style="text-align: right">
      <el-button type="primary" @click="addPayMent">{{ buttonName }}</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import {addPayment, updatePayment} from "../../../network/hydropowerApi";

export default {
  name: "payDialog",
  data() {
    return {
      updateData: []
    }
  },
  methods: {
    //添加缴费
    addPayMent() {
      this.updateData.companyUuid = this.uuid
      addPayment(this.updateData).then(res => {
        console.log(res)
        if (res.code === 2000) {
          this.$emit("success")
        }
      })

    },
    //修改缴费
    paymentUpdate() {
      updatePayment(this.updateData).then(res => {
        if (res.code === 2000) {
          this.$emit("success")
        } else {
          this.$message({
            message: res.message,
            type: "error"
          })
        }
      })
    },
  },
  props: ["update", "buttonName", "uuid"],
  watch: {
    "update": {
      handler() {
        this.updateData = this.update
      }
    }
  },
  mounted() {
    this.updateData = this.update
    // if(this.buttonName) {
    //   this.updateData.amount = ""
    //   this.updateData.type = ""
    // }

  },
}
</script>

<style scoped>

</style>